from db import to_dict, to_list_dict
from fastapi import Depends, Request, WebSocket
from utils.service import ServiceRouter
from models.drugData import requestDrogData
from db.models import Drug
class UserRouter(ServiceRouter):
    def __init__(self):
        super().__init__('/drug', data={'description': {'get': 'get:获取药品信息', "post": "添加药品"}})

    async def get(self, user=Depends(ServiceRouter.auth.Certification)):
        role = (await user.role)[0]
        data = to_dict(user, fields_data=['password', 'create_time', '_role'])
        data['role_id'] = role.id
        data['name'] = role.name
        return self.res(data=data)

    async def post(self,data:requestDrogData,user=Depends(ServiceRouter.auth.Certification)):
        await Drug.create(**data.model_dump_json())
        return self.res(code=200,message="添加成功")


